//
//  HHomeCollectionViewCell.m
//  NursingManage
//
//  Created by Zhen Huang on 17/5/12.
//  Copyright © 2017年 huangzhen. All rights reserved.
//

#import "HHomeCollectionViewCell.h"

@implementation HHomeCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setUpLayout];
        
    }
    return self;
}


- (void)setUpLayout {
    
    NSInteger defaultMenuIconHeight = 45;
    NSInteger defaultMenuNameHeight = 30;
    NSInteger defautlMenuNamePadingTopToMenuIcon = 5;
    
    self.MenuIcon = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, defaultMenuIconHeight, defaultMenuIconHeight)];
    self.MenuName = [[UILabel alloc]initWithFrame:CGRectMake(0 , 0, self.contentView.width, defaultMenuNameHeight)];
    self.MenuName.textColor = [UIColor blackColor];
    self.MenuName.font = [UIFont systemFontOfSize:15];
    self.MenuName.textAlignment = NSTextAlignmentCenter;
    self.MenuName.adjustsFontSizeToFitWidth = YES;
    self.MenuName.lineBreakMode = NSLineBreakByWordWrapping;
    self.MenuName.numberOfLines = 0;

    CGSize maximumLabelSize = CGSizeMake(self.contentView.width, 9999);//labelsize的最大值
    
    //关键语句
    
    CGSize expectSize = [self.MenuName sizeThatFits:maximumLabelSize];
    
    
    self.MenuName.frame = CGRectMake(0, 0,self.contentView.width, expectSize.height);
    
    

    
    self.MenuIcon.center = self.contentView.center;
    self.MenuIcon.top = (self.contentView.height - defaultMenuIconHeight - defaultMenuNameHeight - defautlMenuNamePadingTopToMenuIcon) / 2;
    
    self.MenuName.center = self.contentView.center;
    self.MenuName.top = self.MenuIcon.bottom + defautlMenuNamePadingTopToMenuIcon;
    
    
    
    // 撤消注释可以查看 每个 item 长宽
//    self.MenuName.backgroundColor = UIColor.blueColor;
//    self.contentView.layer.borderColor = [UIColor redColor].CGColor;
//    self.contentView.layer.borderWidth = 1;
    
    [self.contentView addSubview:self.MenuIcon];
    [self.contentView addSubview:self.MenuName];
}

@end
